<?php
include_once("ThePage.class.php");
$page = new ThePage();
if($page->check_login()){
	jumpPage('index.php');
}else{
	if($_POST){
		if($user_id = login()){
			$page->userRequest->set('u_id',$user_id);
		}else{
			alertMsg('-5000');
		}
	}else{
		$page->smarty->display('login.tpl');
	}
}

function login(){
	$user_name = isset($_POST['user_name']) ? $_POST['user_name'] : '';
	$user_password = isset($_POST['user_password']) ? md5($_POST['user_password']) : '';
	if($user_name && $user_password){
		$user_db = Factory::getDB('demo_user');
		$where = "user_name = '{$user_name}' or user_password = '{$user_password}'";
		$arr = $user_db->getAll($where);
		return $arr[0]['user_id'];
	}else{
		return 0;
	}
}
?>